﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Web;

namespace SmartSpace.News.UI.Parts
{
    public partial class EditArticle : SsPart
    {
        private Guid _articleId { get; set; }

        public EditArticle()
            : base(new Guid("{502C6225-C8AD-4F90-BF13-AFBC5054E657}"))
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            _articleId = Request.GetGuid("news_article_id");

            if (!IsPostBack)
            {
                NewsService service = new NewsService();
                Article article = service.GetArticle(_articleId).Data;
                if (article != null)
                {
                    _ctlTitle.Text = article.Title;
                    _ctlDesc.Text = article.Description;
                    _ctlContent.Text = article.Content;
                    _ctlCode.Text = article.Code;
                }
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            NewsService service = new NewsService();
            Article article = service.GetArticle(_articleId).Data;
            if (article != null)
            {
                article.Title = _ctlTitle.Text;
                article.Description = _ctlDesc.Text;
                article.Content = _ctlContent.Text;
                service.SaveArticle(article);
            }
        }
    }
}